﻿$(function() {
    $("form").validate({
        rules: {
            loginName: {
                required: true
            },
            pwd: {
                required: true,
                minlength: 6
            }
        },
        messages: {
            loginName: {
                required: "用户名不允许为空!"
            },
            pwd: {
                required: "密码不能为空!",
                minlength: "密码最小长度为6!"
            }
        },
        submitHandler: function() {
            $("#btn_login").attr("disabled", "disabled").after("<span style='color:red;padding:3px;margin:3px;'>登陆中... ...</span>");
            $.ajax({
                type: "post",
                url: "../API/User.ashx",
                data: { type: 'login', name: $("#loginName").val(), pwd: $("#pwd").val(), r: Math.random() },
                dataType: "html",
                success: function(data) {
                    if (data == 1) {
                        window.location.href = "../Default.aspx";
                    } else {
                        $("span").remove();
                        $("#btn_login").parent().after("<span style='color:red;padding:3px;margin:3px;'>用户名或密码错误！</span>");
                    }
                    $("#loginName").val("");
                    $("#pwd").val("");
                    $("#btn_login").attr("disabled", "");
                }
            });
        }
    });
});